//DAOFactory.java
//Fabrica do AbstractFactory
package dao;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Diego Heusser
 * @author Eder Schramm
 */
public abstract class DAOFactory {


    public abstract AutomovelDAO getAutomovelDAO();
    
    public abstract MotoristaDAO getMotoristaDAO();
    
    public static DAOFactory getDAOFactory() {
        try {
            File file = new File("arquivo/configfabrica.txt");
            FileReader reader = new FileReader(file);
            BufferedReader buffer = new BufferedReader(reader);
            String numero = buffer.readLine();
            numero = numero.substring(8, numero.length());
            int n = Integer.parseInt(numero);
            buffer.close();
            reader.close();

            switch (n) {
                case 0:
                    return new dao.ArquivoBinarioDAOFactory();
                case 1:
                    return new dao.JDBCDAOFactory();
                default:
                    return new dao.JPADAOFactory();
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
